<template>
  <div>
    <input type="text" v-model="kw" />
    <div class="list">
      <router-link :to="'/detail?id='+item.id" class="item" v-for="item in arr" :key="item.id">
        <img :src="$pre+item.img" alt />
        <p>{{item.goodsname}}</p>
        <p>{{item.price}}</p>
        <!-- <p class="title">
          <span>{{item.title}}</span>
        </p>
        <p>
          <span>{{item.con}}</span>
          <span>{{item.goodCons}}</span>
        </p>-->
      </router-link>
    </div>
  </div>
</template>

<script>
import { reqSearch } from "../../http/api";
export default {
  data() {
    return {
      kw: "",
      arr: [],
    };
  },
  watch: {
    kw() {
      if (this.kw === "") {
        this.arr = [];
        return;
      }
      reqSearch({
        keywords: this.kw,
      }).then((res) => {
        console.log(res);
        if (res.data.code) {
          this.arr = res.data.list ? res.data.list : [];
        }
      });
    },
  },
};
</script>

<style scoped>
.list {
  font-size: 0.45rem;
}
.list p {
  margin-bottom: 0.3rem;
}
.list .item {
  display: block;
  /* background: skyblue; */
}
img {
  width: 2rem;
  height: 2rem;
}
</style>